package ybt.demo.web.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import ybt.demo.custom.AjaxResult;
import ybt.demo.entity.SysUser;
import ybt.demo.security.UserUtils;
import ybt.demo.service.SysUserService;

@Controller
@RequestMapping(value = "/password")
public class Passwordcontroller {
	@Autowired
	private SysUserService SysUserService;
	@Autowired
	private UserUtils userUtils;
	
	@RequestMapping(value = "/xg")
	public void edit() {
		
	}
	
	@RequestMapping("/save")
	@ResponseBody
	public Object save(String password1,String password2,String password3) {
		SysUser user=userUtils.getUser();
		BCryptPasswordEncoder encoder=new BCryptPasswordEncoder();
		String password = user.getPassword();
		if(encoder.matches(password1,password)) {
			if(password2.equals(password3)) {
				String encode = encoder.encode(password2);
				user.setPassword(encode);
				SysUserService.save(user);
				return new AjaxResult("logout");
			}
		}
			return  new AjaxResult("请重新修改");
	}
}
